package com.hjj.concurrence.syncMethod.t1;

/**
 * 方法内部的私有变量，不存在线程安全的问题。
 * 方法内部的变量具有私有属性
 */
public class HasSelfPrivateNum {
    public void addI(String username) {
        try {
            int num = 0;
            if (username.equals("a")) {
                num = 100;
                System.out.println("a set over!");
                Thread.sleep(2000);
            } else {
                num = 200;
                System.out.println("b set over!");
            }
            System.out.println(username + " num=" + num);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        HasSelfPrivateNum num = new HasSelfPrivateNum();
        Thread t1 = new ThreadA(num);
        t1.start();
        Thread t2 = new ThreadB(num);
        t2.start();
    }
}
